const net = require("net");

const client = net.createConnection({
  port: 1234,
  host: "127.0.0.1",
});
let dataAarr = ["测试发送1", "测试发送2", "测试发送3"];
client.on("connect", () => {
  // client.write("测试发送1");
  for (let i = 0; i < dataAarr.length; i++) {
    setTimeout(() => {
      client.write(dataAarr[i]);
    }, 1000 * (i + 1));
  }
});

client.on("data", (chunk) => {
  console.log(chunk.toString());
});
client.on("error", (err) => {
  console.log(err);
});
client.on("close", () => {
  console.log("客服端断开连接");
});
